//
//  MarkerBaseView.swift
//  CheckmeRing
//
//  Created by 董鹏 on 2022/2/27.
//

import UIKit

class MarkerBaseView: MarkerView {

    class func configView(chartView: ChartViewBase, title: String, value: String) -> MarkerView {
        let marker = MarkerView(frame: CGRect(x: 20, y: 20, width: 68, height: 40))
        marker.layer.cornerRadius = 6
        marker.layer.masksToBounds = true
        marker.chartView = chartView
        
        let bgLayer1 = CAGradientLayer()
        bgLayer1.colors = [UIColor(red: 0.32, green: 0.32, blue: 0.32, alpha: 1).cgColor, UIColor(red: 0.12, green: 0.12, blue: 0.12, alpha: 1).cgColor]
        bgLayer1.locations = [0, 1]
        bgLayer1.frame = marker.bounds
        bgLayer1.startPoint = CGPoint(x: 0.05, y: 0.2)
        bgLayer1.endPoint = CGPoint(x: 0.86, y: 0.86)
        marker.layer.addSublayer(bgLayer1)
        
        let label = UILabel(frame: CGRect(x: 8, y: 0, width: marker.width, height: marker.height/2))
        label.text = title
        label.textColor = UIColor.white
        label.font = mediumFont(size: 12)
        marker.addSubview(label)
        
        let label1 = UILabel(frame: CGRect(x: 8, y: label.height - 3, width: marker.width, height: marker.height/2))
        label1.textColor = hexColor("FFFFFF", alpha: 0.8)
        label1.font = mediumFont(size: 10)
        marker.addSubview(label1)
        let textStr = "• データ  \(value)"
        let attStr = NSMutableAttributedString(string: textStr)
        attStr.addAttribute(NSAttributedString.Key.font, value: regularFont(size: 14)!, range: (textStr as NSString).range(of: value))
        attStr.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.white, range: (textStr as NSString).range(of: value))
        attStr.addAttribute(NSAttributedString.Key.foregroundColor, value: hexColor("3468E2")!, range: (textStr as NSString).range(of: "•"))
        label1.attributedText = attStr
        return marker
    }

}
